/**
 * Created by dywu on 2015/9/24.
 */
angular.module('app.auth', [
    'ngCookies'
])
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('login', {
            url: "/login",
            templateUrl: login_viewurl+"/auth/login.html",
            controller: 'LoginController'
        })
    ;
}])

//管理员登录

.controller('LoginController', ['$scope','$state','$cookieStore','LoginService', function($scope, $state, $cookieStore, LoginService) {

        $scope.manage = {};
        $cookieStore.remove("manager_cookie");
        $cookieStore.remove("shopid_cookie");
        $scope.loginmanager = function (manager) {
            LoginService.login(manager,function(data){
                $cookieStore.put("manager_cookie", data);
                if(data.sign==0) {
                    $state.go('preferential.user');
                    return;
                }else if(data.sign!=0){
                    LoginService.getbyuserid(data.userid,function(data){
                        if(data.length==0) {
                            alert("不是管理员！");
                            return;
                        }
                        $scope.shops=data[0];
                        $cookieStore.put("shopid_cookie", $scope.shops.shopid);
                        $state.go('preferential.user');
                    },function(){
                        alert("不是管理员！");
                        return;
                    })
                }
            },function(data){
                alert(data.data.reason);
            })
        }
}])

;
